package top.metaspace.singleton.serialization;


import java.io.Serializable;

/**
 * @author panjun
 * @date 2018/6/21. 避免序列化与反序列化破坏单例
 */
public class AvoidSerializationSingleton implements Serializable {
	private static AvoidSerializationSingleton instance = new AvoidSerializationSingleton();


	private AvoidSerializationSingleton() {



	}

	public static AvoidSerializationSingleton getInstance() {
		return instance;
	}

	/**
	 * 在反序列化的时候会自动调用这个方法，这样能保证只产生一个对象
	 * @return
	 */
	private Object readResolve() {
		return instance;
	}
}
